﻿#region The MIT License
// The MIT License
// 
// Copyright (c) 2009 octalforty studios
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#endregion
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.ServiceModel;

using octalforty.Chinchillin.Shared.Deployment.Resources;

namespace octalforty.Chinchillin.Shared.Deployment.Agent
{
    /// <summary>
    /// Provides a way for the Agent to communicate back to client.
    /// </summary>
    /// <remarks>
    /// This used to derive from <see cref="IResourceProvider"/>, but WCF chokes on this.
    /// </remarks>
    public interface IDeploymentCallback
    {
        /// <summary>
        /// Returns a checksum of a resource located at <paramref name="resourceUri"/>.
        /// </summary>
        /// <param name="resourceUri"></param>
        /// <returns></returns>
        [OperationContract()]
        byte[] GetResourceChecksum(Uri resourceUri);

        /// <summary>
        /// Returns a checksum of a resources located at <paramref name="resourcesUris"/>.
        /// </summary>
        /// <param name="resourcesUris"></param>
        /// <returns></returns>
        [OperationContract()]
        ResourceInfo[] GetResourcesChecksums(Uri[] resourcesUris);

        /// <summary>
        /// Opens and returns a read-only stream for resource at <paramref name="resourceUri"/>.
        /// </summary>
        /// <param name="resourceUri"></param>
        /// <returns></returns>
        [OperationContract()]
        Stream GetResourceStream(Uri resourceUri);

        /// <summary>
        /// Returns a hierarchy of all resources under <paramref name="baseResourceUri"/>.
        /// </summary>
        /// <param name="baseResourceUri"></param>
        /// <returns></returns>
        [OperationContract()]
        Uri[] GetResourcesHierarchy(Uri baseResourceUri);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="serverTimestamp"></param>
        /// <param name="eventType"></param>
        /// <param name="eventCode"></param>
        /// <param name="eventMessage"></param>
        [OperationContract()]
        void TraceEvent(string serverName, DateTime serverTimestamp, TraceEventType eventType, int eventCode, string eventMessage);
    }

    [DataContract()]
    public class ResourceInfo
    {
        [DataMember()]
        public Uri Uri
        { get; set; }

        [DataMember()]
        public byte[] Checksum
        { get; set; }

        public ResourceInfo()
        {
        }

        public ResourceInfo(Uri uri, byte[] checksum)
        {
            Uri = uri;
            Checksum = checksum;
        }
    }
}
